#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define endl '\n'
#define f(n) for(int i=0 ;i<n;i++)
#define fj(n) for(int j=0 ;j<n;j++)
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define fast cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
int dx[] = { +0, +0, -1, +1, +1, +1, -1, -1 };
int dy[] = { -1, +1, +0, +0, +1, -1, +1, -1 };
using namespace std;
// p not com / p1*p2 not com
// p*p || p*p*p com
// we can make com num from 2 same prime num or 3 diff primes
int main()
{
fast
int T; cin>>T;
while (T--)
{
string s; cin>>s;
int ans=1e9;
for(char ch='a';ch<='z';ch++)
{
int cnt=0,dis=0,moves=0;
f(s.size())
{
if(s[i]==ch)dis=max(dis,cnt),cnt=0;
else cnt++;
}
dis=max(dis,cnt);
while (dis)
{
moves++;
dis/=2;
}
ans=min(ans,moves);
}
cout<<ans<<endl;
}
return 0;
}
Divisible | Three primes |
Coprimes | Cost of balloons |
One String No Trouble | Help Jarvis! |
Lift queries | Goki and his breakup |
Ali and Helping innocent people | Book of Potion making |
Duration | Birthday Party |
e-maze-in | Bricks Game |
Char Sum | Two Strings |
Anagrams | Prime Number |
Lexical Sorting Reloaded | 1514A - Perfectly Imperfect Array |
580A- Kefa and First Steps | 1472B- Fair Division |
996A - Hit the Lottery | MSNSADM1 Football |
MATCHES Playing with Matches | HRDSEQ Hard Sequence |
DRCHEF Doctor Chef | 559. Maximum Depth of N-ary Tree |
821. Shortest Distance to a Character | 1441. Build an Array With Stack Operations |